﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics.OpenGL;

namespace _2D_Game
{
    class Square
    {
        public Square(int x, int y, int w, int h)
        {
            X = x;
            Y = y;
            Width = w;
            Height = h;
        }

        public int X { get; set; }
        public int Y { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }

        private int _textureId;

        public bool SetTexture(int texId)
        {
            if (!TextureManager.TextureExists(texId))
                return false;
            _textureId = texId;
            return true;
        }

        public void Render()
        {
            GL.PushMatrix();
            GL.Translate(X, Y, 0);
            GL.BindTexture(TextureTarget.Texture2D, _textureId);
            GL.Begin(BeginMode.Quads);
            {
                GL.TexCoord2(0, 0); GL.Vertex2(-Width/2, -Height/2);
                GL.TexCoord2(1, 0); GL.Vertex2(Width/2, -Height/2);
                GL.TexCoord2(1, 1); GL.Vertex2(Width/2, Height/2);
                GL.TexCoord2(0, 1); GL.Vertex2(-Width/2, Height/2);
            }
            GL.End();
            GL.PopMatrix();
        }
    }
}
